package com.zxbit.flash.presenter;

import com.zxbit.flash.BuildConfig;
import com.zxbit.flash.base.BasePresenter;
import com.zxbit.flash.common.UserInfo;
import com.zxbit.flash.mvpview.AlertDialogMvpView;
import com.zxbit.flash.network.CustomConsumer;
import com.zxbit.flash.network.ParamsFactory;
import com.zxbit.flash.response.AlertDialogResponse;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.functions.Consumer;

public class AlertDialogPresenter extends BasePresenter {
    private AlertDialogMvpView mvpView;

    public AlertDialogPresenter(AlertDialogMvpView mvpView) {
        this.mvpView = mvpView;
    }

    /**
     * 获取首页的弹框消息
     */
    public void getDialogInfo() {
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("channel", BuildConfig.channel);
        toSubScribe(req.getAlertInfo(UserInfo.getToken(), ParamsFactory.getCommonParams(null)),
                new CustomConsumer<AlertDialogResponse>() {
            @Override
            public void call(AlertDialogResponse response) {
                mvpView.onGetDataNext(response);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                mvpView.onGetDataError(throwable);
            }
        });
    }
}
